﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

using ECS.DAL;
namespace ECS.Framework
{
    
    public static class CommonResourceString
    {
      
        public enum ConstantString
        {
            INVALID_NUMBER_FORMAT,
            INVALID_MAWB_LAST_DIGIT,
            INVALID_USER_ID,
        }
        #region private properties
        private const string MSG_INVALID_NUMBER_FORMAT = "Invalid number format";
        private const string MSG_INVALID_MAWB_LAST_DIGIT = "Invalid MAWB Check Digit";
        private const string MSG_INVALID_USER_ID = "Invalid User ID";
        private static DataSet resource;
        #endregion

        #region public methods

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string GetResourceString(ConstantString value)
        {
            switch (value)
            { 
                case ConstantString.INVALID_NUMBER_FORMAT:
                    return MSG_INVALID_NUMBER_FORMAT;
                case ConstantString.INVALID_MAWB_LAST_DIGIT:
                    return MSG_INVALID_MAWB_LAST_DIGIT;
                case ConstantString.INVALID_USER_ID:
                    return MSG_INVALID_USER_ID;
                default:
                    return string.Empty;
            }

        }
        public static void LoadResource(string appId, int locale, string device, string userId)
        {
           
            try
            {
                resource = new DataSet();
                using(Entities entity = new Entities())
                {
                    entity.Open();
                    DbCommand cmd = entity.CreateCommand("usp_LoadResources");
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(entity.CreateParameter("@in_vchApplicationID", appId));
                    cmd.Parameters.Add(entity.CreateParameter("@in_intLocaleID", locale));
                    cmd.Parameters.Add(entity.CreateParameter("@in_vchResourceName", null));
                    cmd.Parameters.Add(entity.CreateParameter("@in_vchDevice", device));
                    cmd.Parameters.Add(entity.CreateParameter("@in_vchUserID", userId));

                    DbDataAdapter adapter = entity.CreateDataAdapter(cmd);
                    adapter.Fill(resource);
                }
            }
            catch (Exception ex)
            {

                CommonMessageBox.ShowMessageError(ex);
            }
        }
        public static string GetResourseValue(string resourseName)
        {
            string value = string.Empty;
            try
            {
                for (int i = 0; i < resource.Tables[0].Rows.Count; i++)
                {
                    if (resource.Tables[0].Rows[i]["resource_name"].ToString().Trim().Equals(resourseName))
                    {
                        value = resource.Tables[0].Rows[i]["value"].ToString();
                        break;
                    }

                }
            }
            catch (Exception ex)
            {
                CommonMessageBox.ShowMessageError(ex);       
            }
            return value;
        }
        #endregion
    }
}
